from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response


class CustomPagination(PageNumberPagination):
    page_size = 13  # 默认每页条数
    page_size_query_param = 'page_size'  # 允许客户端通过此参数指定每页条数
    max_page_size = 50  # 每页最大条数限制

    def get_paginated_response(self, data):
        return Response({
            'code': 1,
            'count': self.page.paginator.count,
            'next': self.get_next_link(),
            'previous': self.get_previous_link(),
            'results': data,
        })
